"""
元素控件处理模块
"""
import pyautogui
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from uiautomation import *
import uiautomation

root_driver = None
pyautogui.FAILSAFE = False
pyautogui.PAUSE = 1


def wait_element_by_ua(locator: dict):
    """
     基于uiautomation获取控件
    :param locator: 控件属性，eg，{"ControlType": "MenuItemControl", "Name": 'New'}
    :return:
    """
    if 'ControlType' not in locator:
        print('控件属性中缺少"ControlType"属性')
    try:
        control_type = locator.get('ControlType')
        element = getattr(uiautomation, control_type)(**locator)
        print(f'通过{locator}成功定位控件,控件Name值为"{element.Name}"')
        return element
    except Exception as e:
        print(f'无法通过{locator}定位到控件元素!!!!!!')


if __name__ == '__main__':
    res = wait_element_by_ua(locator={"ControlType": "MenuItemControl", "Name": 'New'})
    print(res)
